﻿
@using Model
@model salary_standard_View
<script src="~/javascript/jquery-1.7.2.js"></script>
<script src="~/Scripts/vue.js"></script>
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<link href="~/lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
@* ***********薪酬标准登记************ *@

<body>
    <div id="data">
        <form method="post" action="salarystandard_register_success.html" id="form1">
            <table width="100%">
                <tr>
                    <td>
                        <font color="black">
                            您正在做的业务是：人力资源--薪酬标准管理--薪酬标准登记
                        </font>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <input type="button" value="提 交" v-on:click="register()" class="btn-default">
                        <input type="reset" value="返 回"  class="btn-default">
                    </td>
                </tr>
            </table>
            <table id="stable" width="100%" border="1" cellpadding=0 cellspacing=1
                   bordercolorlight=#848284 bordercolordark=#eeeeee
                   class="table-hover">
                <tr>
                    <td width="74" style="background-color:darkgray">
                        薪酬标准编号
                    </td>
                    <td width="168" class="TD_STYLE2">
                        <input type="text" asp-for="standard_id" class="INPUT_STYLE2" id="standard_id" readonly="readonly">
                    </td>
                    <td width="83" style="background-color:darkgray">
                        薪酬标准名称
                    </td>
                    <td width="171" class="TD_STYLE2">
                        <input type="text" asp-for="standard_name" class="INPUT_STYLE2">
                    </td>
                    <td width="170" style="background-color:darkgray">
                        薪酬总额
                    </td>
                    <td width="138" class="TD_STYLE2">
                        <input type="text" asp-for="salary_sum" value="0.0" readonly class="INPUT_STYLE2" />
                    </td>
                    <td width="103" style="background-color:darkgray">
                        &nbsp;
                    </td>
                    <td width="95" height="26" class="TD_STYLE2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="TD_STYLE1"style="background-color:darkgray">
                        制定人
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" asp-for="designer" class="INPUT_STYLE2">
                    </td>
                    <td class="TD_STYLE1"style="background-color:darkgray">
                        登记人
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" asp-for="register" class="INPUT_STYLE2"></input>
                    </td>
                    <td class="TD_STYLE1"style="background-color:darkgray">
                        登记时间
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" asp-for="regist_time" class="INPUT_STYLE2">
                        <span asp-validation-for="regist_time" class="text-danger"></span>
                    </td>
                    <td class="TD_STYLE1"style="background-color:darkgray">
                        &nbsp;
                    </td>
                    <td class="TD_STYLE2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="TD_STYLE1"style="background-color:darkgray">
                        备注
                    </td>
                    <td colspan="7" class="TD_STYLE2">
                        <textarea asp-for="remark" rows="4" class="TEXTAREA_STYLE1"></textarea>
                    </td>
                </tr>
                <tr class="TD_STYLE1"style="background-color:darkgray">
                    <td align="center">
                        序号
                    </td>
                    <td colspan="3">
                        薪酬项目名称
                    </td>
                    <td>
                        金额
                    </td>
                    <td colspan="3">
                        &nbsp;
                    </td>
                </tr>
                <tbody id="tbody">
                    @foreach (config_public_char item in ViewBag.s)
                    {
                        <tr class="TD_STYLE2">
                            <td align="center"style="background-color:darkgray">
                                @item.pbc_id

                                <input type="hidden" name="itemId" value="@item.pbc_id">
                            </td>
                            <td colspan="3">
                                @item.attribute_name
                                <input type="hidden" id="details1" name="itemName" value="@item.attribute_name">
                            </td>
                            <td>
                                <input type="text" id="salary" value="0.00" name="salary" onkeyup="countMoney('6','salary')" />
                            </td>
                            <td colspan="3">
                                &nbsp;
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            <p>
                &nbsp;
            </p>
        </form>

    </div>
    <script>
        var vm = new Vue({
            el: "#data",
            data: {
                num: 0
            },
            methods: {
                //添加salary_standard数据
                register: function () {
                    var t = this;
                    $.ajax({
                        url: "/salaryCriterion/salarystandard",
                        type: "post",
                        data: $("#form1").serialize(),
                        success: function (zhi) {
                            var data = eval("(" + zhi + ")");
                            if (data == "T") {
                                t.register2();
                            } else {
                                alert("添加失败");
                            }
                        }
                    })
                },
                //添加salary_standard_details数据
                register2: function () {
                    var t = this;
                    for (var i = 0; i < 6; i++) {
                        var item_id = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(1) input").val();
                        var item_name = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(2) input").val();
                        var salary = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(3) input").val();
                        if (salary > 0.0) {
                            $.ajax({
                                url: "/salaryCriterion/register2",
                                type: "post",
                                data: {
                                    "item_name": item_name,
                                    "standard_id": $("#standard_id").val(),
                                    "item_id": item_id,
                                    "standard_name": $("#standard_name").val(),
                                    "salary": salary
                                },
                                success: function (msg) {
                                    var data = eval("(" + msg + ")");
                                    if (data == "T2") {
                                        location.href = '/salaryCriterion/salarystandard_change_list';
                                    } else {
                                        alert("添加失败");
                                    }
                                }
                            });
                        }
                    }
                },
                //ID随机数
                standarid: function () {
                    var randoms = [];
                    while (true) {
                        var isExists = false;
                        //获取一个10-100范围的数
                        var random = parseInt(10 + (90 - 10) * (Math.random()));
                        //判断当前随机数是否已经存在
                        for (var i = 0; i < randoms.length; i++) {
                            if (random === randoms[i]) {
                                isExists = true;
                                break;
                            }
                        }
                        // 如果zhi不存在，则添加进去
                        if (!isExists)
                            randoms.push(random);
                        // 如果有10位随机数了，就跳出
                        if (randoms.length === 2)
                            break;
                    }
                    //把数组中的','用空代替
                    randoms = randoms.join('');
                    var data = new Date();
                    var year = data.getFullYear();
                    var month = data.getMonth() + 1;
                    var day = data.getDate();
                    var Time = data.getHours();
                    var branch = data.getMinutes();
                    var second = data.getSeconds();
                    $("#standard_id").val("No" + year + month + day + Time + branch + second + randoms);
                }
            },
            mounted: function () {
                this.standarid();
            }
        });
        //金额总数
        function countMoney(obj, o) {

            if (isNaN(document.getElementById(o).value) || document.getElementById(o).value < 0) {
                alert("金额填写错误!");
                document.getElementById(o).value = "0.00";
                return;
            }
            var sum = 0;
            for (var i = 1; i <= obj; i++) {
                var salary = $("#tbody tr:nth-child(" + i + ") td:nth-child(3) input").val();
                if (salary == null || salary == "" || salary == NaN || salary == "0.00") {
                    salary = 0;
                }
                sum = Number(sum) + Number(salary);

            }
            document.getElementById("salary_sum").value = sum;

        }
        //当前时间计时器
        function time() {
            var tdate = document.getElementById("regist_time");
            var d = new Date();
            var y = d.getFullYear();
            var moth = d.getMonth() + 1;
            var date = d.getDate();
            var h = d.getHours();
            var m = d.getMinutes();
            var s = d.getSeconds();
            var hh = 20 - 1 - h;
            var mm = 60 - 1 - m;
            var ss = 60 - s;
            if (hh > 0) {
                mm = mm + 60 * hh;
            }
            if (moth < 10) {
                moth = "0" + moth;
            }
            if (date < 10) {
                date = "0" + date;
            }
            if (h < 10) {
                h = "0" + h;
            }
            if (m < 10) {
                m = "0" + m;
            }
            if (s < 10) {
                s = "0" + s;
            }
            if (mm < 10) {
                mm = "0" + mm;
            }
            if (ss < 10) {
                ss = "0" + ss;
            }

            tdate.value = y + "-" + moth + "-" + date + " " + h + ":" + m + ":" + s;

        }
        window.onload = time;
        var out = window.setInterval(time, 1000);

      
    </script>
</body>
